﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Bean.Entity;
using Bean.Infrastructure;
using Bean.Repository;
using Bean.Service.IService;
using Microsoft.Extensions.Logging;

namespace Bean.Service.Service
{
    /// <summary>
    /// 政策关键字服务
    /// </summary>
    public class PolicyKeyWordService : IPolicyKeyWordService, ITransientService
    {
        private readonly ILogger<PolicyKeyWordService> _logger;

        private readonly IRepository<PolicySysRule> _policySysRuleRepository;

        public PolicyKeyWordService(ILogger<PolicyKeyWordService> logger, IRepository<PolicySysRule> policySysRuleRepository)
        {
            _logger = logger;
            _policySysRuleRepository = policySysRuleRepository;

        }

        public async Task<IEnumerable<PolicySysRuleDto>> GetListAsync(List<string> keyWords)
        {
            var response = await _policySysRuleRepository
                .AsQueryable()
                .Where(w => w.IsActive == 1&&keyWords.Contains(w.PolicyKeyWord))
                .Select(s => new PolicySysRuleDto
            {
                PolicyKeyWord = s.PolicyKeyWord,
                SysPolicyRuleId = s.SysPolicyRuleId,
                SysRuleName = s.SysRuleName,

            }).ToListAsync();

            //var db = _policySysRuleRepository.AsSugarClient();

            

            return response;
        }
    }
}
